package com.yanqu.road.server.cmd.union.cross.trade;

import com.yanqu.road.entity.enums.eRedHotNotifyType;
import com.yanqu.road.pb.worldmessage.WorldMessageProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.union.CrossUnionReqContext;
import com.yanqu.road.server.manager.union.trade.CrossUnionTradeMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.C_UNION_TRADE_SYNC_RED_DOT, desc = "登录红点")
public class CrossUserRedDotCmd extends CrossCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {

        CrossUnionReqContext context = CrossUnionReqContext.initContext(serverId, packet.getPlayerId()).loadUnionMember().loadUnionInfo();

        if(context.getRet() == 0) {
            boolean canJoin = CrossUnionTradeMgr.hasRouteCanJoin(context.getUnionInfo().getUnionUid(), context.getMember());
            WorldMessageProto.RedHotNotifyMsg.Builder redHotMsg = CrossUnionTradeMgr.parseRedHotNotifyMsg(eRedHotNotifyType.UnionTradeCanJoin.getValue(), canJoin ? 1 : 0, null);

            MessageHelper.sendPacket(serverId, packet.getPlayerId(), YanQuMessageUtils.buildMessage(Protocol.U_RED_HOT_NOTIFY, redHotMsg));
        }

    }

    @Override
    public void sendData() {

    }
}
